package com.yc.yuehui.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.yuehui.entity.YhPhotoRace;
import com.yc.yuehui.entity.YhPhotoShow;
import com.yc.yuehui.mapper.YhPhotoRaceMapper;
import com.yc.yuehui.mapper.YhPhotoShowMapper;
import com.yc.yuehui.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyl
 * @since 2023-03-07
 */
@Controller
@RequestMapping("/yuehui/yhPhotoShow")
public class YhPhotoShowController {

    @Resource
    private YhPhotoShowMapper mapper;

    @GetMapping("queryAll")
    @ResponseBody
    public Result queryPage() {
        List<YhPhotoShow> list = mapper.selectAll();
        long count = mapper.countPage();
        if (list == null || list.isEmpty()) {
            return new Result(0, "查无数据", null);
        }
        return new Result(0, "查询成功", list);
    }

    @GetMapping("queryPage")
    @ResponseBody
    public Page<YhPhotoShow> queryNewPage(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int size) {
        List<YhPhotoShow> list = mapper.selectByNewPage((pageNum - 1) * size, size);
        long count = mapper.countPage();
        Page<YhPhotoShow> p = new Page<>(pageNum, size);
        p.setTotal(count);
        p.setRecords(list);
        return p;
    }

    @GetMapping("queryHotPage")
    @ResponseBody
    public Page<YhPhotoShow> queryHotPage(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int size) {
        List<YhPhotoShow> list = mapper.selectByHotPage((pageNum - 1) * size, size);
        long count = mapper.countPage();
        Page<YhPhotoShow> p = new Page<>(pageNum, size);
        p.setTotal(count);
        p.setRecords(list);
        return p;
    }

    @GetMapping("queryPhoto")
    @ResponseBody
    public Result queryPhoto(int id) {
        List<YhPhotoShow> query = mapper.query(id);
        if (query == null){
            return new Result(0,"查无数据",null);
        }
        return new Result(1,"查询成功",query);
    }
}

